<template>
  <view class="g-content">
    <uni-card
      class="card-course"
      v-for="item in list"
      :title="item['课程名']"
      :extra=" '第'+item['课时数']+'节课'"
      :is-shadow="true"
      :id="item['签到号']"
    >
      <button @click="_signUp(item['签到号'])">点击签到</button>  
    </uni-card>
    <div style="height: 120rpx;"></div>
    <hans-tabber :list="tab" class="g-tabbar" style="position:fixed;bottom:0;width:100%;left:0;right:0;" :current="1"></hans-tabber>
  </view>
</template>

<script>
  import Student from '../../../api/Student.js';
  export default {
  	data() {
  		return {
        uid: this.$store.state.token.id,
  			list: [],
        tab: [
          {
          	"text":"今日课程",
          	"pagePath":"today",
          	"iconPath":"../../../static/icon/mail.png",
          	"selectedIconPath":"../../../static/icon/mail.png"
          },
          {
          	"text":"签到信息",
          	"pagePath":"get_sign",
          	"iconPath":"../../../static/icon/task.png",
          	"selectedIconPath":"../../../static/icon/task.png"
          }
        ]
  		}
  	},
    onInit() {
      this.uid = this.$store.state.token.id;
    },
  	onLoad() {      
      this._initList();
  	},
    methods:{
      async _initList(){
        this.Test.log('学生-签到记录-学号',this.uid);
        const rm = (await Student.getSign(this.uid));
        this.Test.log('学生-签到记录-签到表',rm);
        if(rm[1]['statusCode'] == '200'){
          if(rm[1].data == [] || rm[1].data == ''){
            this.Toast.show('无记录');
            this.list = [];
            return;
          }
          this.list = rm[1].data;
          //this.Toast.show('数据已加载');
        }
      },    
      async _signUp(id){
        uni.showLoading();
        this.Test.log('学生-签到记录-签到号',id);
        const rm1 = (await Student.toSign1(this.uid,id));
        this.Test.log('学生-签到记录-签到回执1',rm1);
        const rm2 = (await Student.toSign2(this.uid,id));
        this.Test.log('学生-签到记录-签到回执2',rm2);
        this._initList();
        uni.hideLoading();
      }
    }
  }
</script>

<style>
  .card-course {
    height: 400rpx;
    width: 600rpx;
  }
</style>